package com.example.enjoylearning.login

import android.os.Bundle
import android.util.Log
import android.widget.Toast
import com.example.enjoylearning.api.WanAndroidApi
import com.example.enjoylearning.databinding.ActivityLoginBinding
import com.example.enjoylearning.model.LoginBen
import com.example.enjoylearning.network.ApiClient
import com.example.enjoylearning.network.ApiError
import com.example.enjoylearning.network.ApiResponse
import com.example.enjoylearning.network.NetworkScheduler
import com.trello.rxlifecycle2.components.support.RxAppCompatActivity

class LoginActivity : RxAppCompatActivity(), LoginView {
    lateinit var binding: ActivityLoginBinding
    val presenterImpl: LoginPresenterImpl by lazy {
        LoginPresenterImpl(this)
    }


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityLoginBinding.inflate(layoutInflater)
        setContentView(binding.root)



        binding.button.setOnClickListener {
            val userName = binding.editTextTextPersonName.text.toString()
            val password = binding.editTextTextPersonName2.text.toString()
            presenterImpl.registerWanAndroid(this@LoginActivity,userName,password,password)
        }
        binding.button2.setOnClickListener {

            val userName = binding.editTextTextPersonName.text.toString()
            val password = binding.editTextTextPersonName2.text.toString()
            presenterImpl.loginWanAndroid(this@LoginActivity,userName,password)
        }
    }
    //登录成功
    override fun onLoginSuccess(loginBen: LoginBen) {
        Toast.makeText(this, "$loginBen", Toast.LENGTH_SHORT).show()
    }
    //登录失败
    override fun onLoginFail(message: String) {
        Toast.makeText(this, "$message", Toast.LENGTH_SHORT).show()
    }
    //注册成功
    override fun onRegisterSuccess(loginBean: LoginBen) {
        Toast.makeText(this, "$loginBean", Toast.LENGTH_SHORT).show()
    }
    //注册失败
    override fun onRegisterFail(message: String) {
        Toast.makeText(this, "$message", Toast.LENGTH_SHORT).show()
    }


}